package com.free.chat.entity.model;

import cn.hutool.core.util.IdUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.free.chat.utils.ServletUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.noear.solon.validation.annotation.NotNull;
import org.noear.solon.validation.annotation.Pattern;

import java.io.Serializable;

/**
 * (Users)实体类
 *
 * @author zhbcm
 * @since 2022-10-18 22:18:16
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@TableName("users")
public class Users implements Serializable {

    private static final long serialVersionUID = -71067401907719760L;

    @TableId("id")
    private Long id = IdUtil.getSnowflakeNextId();
    /**
     * 用户名
     */
    @NotNull(message = "用户名不能为空")
    private String username;
    /**
     * 密码
     */
    @NotNull(message = "密码不能为空")
    private String password;
    /**
     * 我的头像，如果没有默认给一张
     */
    private String faceImage;
    /**
     * 头像大图
     */
    private String faceImageBig;
    /**
     * 昵称
     */
    @NotNull(message = "昵称不能为空")
    private String nickname;
    /**
     * 新用户注册后默认后台生成二维码
     */
    private String qrcode;
    /**
     * 手机号
     */
    @Pattern(value = "^1[3|4|5|7|8][0-9]\\d{4,8}$", message = "手机号格式不正确")
    private String mobile;

    /**
     * 昵称首字母
     */
    private String firstWord;

    public String getFirstWord() {
        String word = PinyinUtil.getPinyin(nickname).substring(0, 1).toUpperCase();
        if (!word.matches("^[A-Z]*")) return "#";
        return word;
    }
}

